package com.gylang.sso.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * @author gylang,
 * @data 2019/12/8 17:59,
 * @DESC
 */
public class HttpUtils {


    public static void returnJson(int code, String msg, HttpServletResponse response) throws IOException {
        response.setContentType("application/json;charset=utf-8");
        response.setStatus(code);
        PrintWriter out = response.getWriter();
        Map result = new HashMap();
        result.put("code", code);
        result.put("msg", msg);
        out.write(new ObjectMapper().writeValueAsString(result));
        out.flush();
        out.close();
    }
}
